package com.x.erp.manage;

import com.x.erp.dao.MultilevelActivityShareDao;
import com.x.erp.model.MultilevelActivity;
import com.x.erp.model.MultilevelActivityShare;
import com.x.framework.manage.BaseManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MultilevelActivityShareManage extends BaseManage{

	@Autowired
	private MultilevelActivityShareDao multilevelActivityShareDao;// 多级营销活动保证金管理

	public MultilevelActivityShare insertMultilevelActivityShare(MultilevelActivityShare multilevelActivityShare) throws Exception {
		MultilevelActivityShare share = new MultilevelActivityShare();
		share.setUserId(multilevelActivityShare.getUserId());
		share.setActivityId(multilevelActivityShare.getActivityId());
		List<MultilevelActivityShare> shares = multilevelActivityShareDao.selectMultilevelActivityShareList(share);
		if(!shares.isEmpty() && shares.get(0).getShareState() != 0){
			return shares.get(0);
		}
		return this.insert(multilevelActivityShare);
	}

}
